<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 最长字符串链 -->
    <script>
      var longestStrChain = function (words) {
        words.sort((a, b) => a.length - b.length)
        let dp = new Map()
        let res = 0
        for (let i = 0; i < words.length; i++) {
          let word = words[i]
          let max = 0
          for (let j = 0; j < word.length; j++) {
            let prev = word.slice(0, j) + word.slice(j + 1)
            max = Math.max(max, (dp.get(prev) || 0) + 1)
          }
          dp.set(word, max)
          res = Math.max(res, max)
        }
        return res
      }
      console.log(longestStrChain(['a', 'b', 'ba', 'bca', 'bda', 'bdca']))
    </script>
  </body>
</html>
